package com.ruoyi.web.controller.warning;


import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.warning.domain.query.EventQuery;
import com.ruoyi.warning.service.IEventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 告警模版表 前端控制器
 * </p>
 *
 * @author chenhc
 * @since 2025-02-20
 */
@RestController
@RequestMapping("/event")
@Api(tags = "事件", description = "用于处理事件相关操作的控制器")
public class EventController {
    @Resource
    private IEventService iEventService;
    @ApiOperation("事件分页")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/page")
    public R<TableDataInfo> page(EventQuery query)
    {
        return R.ok(iEventService.getEventPage(query));
    }

    @ApiOperation("事件列表")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/list")
    public R list(EventQuery query)
    {
        return R.ok(iEventService.getEventList(query));
    }
    
    @Anonymous
    @ApiOperation("手动刷新事件")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/refresh")
    public R refresh() throws Exception {
        return R.ok(iEventService.refresh());
    }

    @ApiOperation("获取图片地址")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/pictureUrl")
    public R pictureUrl(String id){
        return R.ok(iEventService.pictureUrl(id));
    }

    @ApiOperation("获取视频")
    @Anonymous
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/video")
    public void video(String id, HttpServletResponse response) throws Exception {
        iEventService.video(id,response);
    }

    @ApiOperation("接收事件")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @Anonymous
    @PostMapping(value = "/receiveEvent")
    public R receiveEvent(@RequestBody Object obj) throws Exception {
        iEventService.receiveEvent(obj);
        return R.ok();
    }

}
